package com.zzyl.controller.nursing;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {
    private final NursingPlanService nursingPlanService;

    public NursingPlanController(NursingPlanService nursingPlanService) {
        this.nursingPlanService = nursingPlanService;
    }

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<NursingPlanVo> selectAll() {
        List<NursingPlanVo> nursingPlanVoList = nursingPlanService.selectAll();
        return ResponseResult.success(nursingPlanVoList);
    }

    @GetMapping("/search")
    @ApiOperation("条件分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> selectByPage(
            @ApiParam(value = "护理项目名称") String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingPlanVo> nursingPlanPageInfo = nursingPlanService.selectByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingPlanPageInfo);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划(包含项目)(数据回显)")
    public ResponseResult<NursingPlanVo> selectById(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.selectById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation("新增护理计划(包含项目)")
    public ResponseResult insert(@RequestBody NursingPlanDto nursingPlanDto) {
        int row = nursingPlanService.insert(nursingPlanDto);
        return this.toAjax(row);
    }

}
